package org.lanqiao.ssm.web.auth.controller;

import javax.annotation.Resource;

import org.lanqiao.ssm.common.facede.BaseManagerFacedeI;
import org.lanqiao.ssm.common.facede.BaseQueryFacedeI;
import org.lanqiao.ssm.common.model.EasyuiModel;
import org.lanqiao.ssm.common.model.Json;
import org.lanqiao.ssm.common.util.ModelConvertUtil;
import org.lanqiao.ssm.common.web.controller.BaseController;
import org.lanqiao.ssm.facede.auth.facede.RoleManagerFacedeI;
import org.lanqiao.ssm.facede.auth.facede.RoleQueryFacedeI;
import org.lanqiao.ssm.facede.auth.model.Role;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;

@SuppressWarnings("all")
@RestController
@RequestMapping("/role")
public class RoleController extends BaseController<Role, String> {
	@Resource
	private RoleManagerFacedeI roleManagerFacede;
	@Resource
	private RoleQueryFacedeI roleQueryFacede;

	@Override
	public BaseManagerFacedeI<Role, String> getManagerFacede() {
		return roleManagerFacede;
	}

	@Override
	public BaseQueryFacedeI<Role, String> getQueryFacede() {
		return roleQueryFacede;
	}

	@RequestMapping(value = "/findRoleResources", method = RequestMethod.GET)
	public EasyuiModel<Role> findRoleResources(Role role, int page, int rows) throws Exception {
		PageInfo<Role> findRoleResources = roleQueryFacede.findRoleResources(role, page, rows);
		return ModelConvertUtil.pageInfo2EasyuiModel(findRoleResources);
	}

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public Json add(Role role) throws Exception {

		return roleManagerFacede.add(role) > 0 ? setSimpleSuccess(role) : setFailed();
	}

	@RequestMapping(value = "/remove", method = RequestMethod.POST)
	public Json remove(String id) throws Exception {
		return roleManagerFacede.remove(id) > 0 ? setSimpleSuccess(id) : setFailed();

	}

	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public Json edit(Role role) throws Exception {

		return roleManagerFacede.edit(role) > 0 ? setSimpleSuccess(role) : setFailed();
	}

	@RequestMapping(value = "/combogrid", method = RequestMethod.GET)
	public EasyuiModel<Role> combogrid(Role role, int page, int rows) throws Exception {
		PageInfo<Role> findRoleResources = roleQueryFacede.findRoleResources(role, page, rows);
		return ModelConvertUtil.pageInfo2EasyuiModel(findRoleResources);
	}

	@RequestMapping(value = "/editMenu", method = RequestMethod.POST)
	public Json editMenu(Role role) throws Exception {

		return roleManagerFacede.editMenu(role) > 0 ? setSimpleSuccess(role) : setFailed();
	}

	@RequestMapping(value = "/getMenuIdsByPrimaryKey", method = RequestMethod.GET)
	public Json getMenuIdsByPrimaryKey(String roleId) throws Exception {
		return setSimpleSuccess(roleManagerFacede.getMenuIdsByPrimaryKey(roleId));
	}

}
